package cn.lyh.gulimall.member.controller;

import cn.lyh.gulimall.member.entity.UmsMember;
import cn.lyh.gulimall.member.entity.UmsMemberLevel;
import cn.lyh.gulimall.member.service.UmsMemberLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.PageUtils;
import utils.R;

import java.util.List;
import java.util.Map;

/**
 * @author lyh
 * @version 1.0
 * @since 2021/4/28
 */
@RequestMapping("/member/memberlevel")
@RestController
public class MemberLevelController {


	@Autowired
	UmsMemberLevelService memberLevelService;

	@GetMapping("/list")
	public R getMemberLeveList(@RequestParam Map<String, Object> params){
		PageUtils leveListByPage = memberLevelService.getLeveListByPage(params);
		return R.ok().put("page",leveListByPage);
	}

	@PostMapping("/save")
	public R saveMemberLeveInfo(@RequestBody UmsMemberLevel umsMemberLevel){
		memberLevelService.save(umsMemberLevel);
		return R.ok();
	}

	@PostMapping("/delete")
	public R deleteMemberLevelInfo(@RequestBody List<Long> ids){
		memberLevelService.removeByIds(ids);
		return R.ok();
	}

	@GetMapping("/info/{id}")
	public R getMemberLevelInfo(@PathVariable String id){
		UmsMemberLevel byId = memberLevelService.getById(id);
		return R.ok().put("memberLevel",byId);
	}

	@PostMapping("/update")
	public R updateMemberLevelById(@RequestBody UmsMemberLevel memberLevel){
		memberLevelService.updateById(memberLevel);
		return R.ok();
	}

}
